/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TableModels;

import Business.BoothProductManage;
import Entities.BoothProduct;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Nhit
 */
public class ProductTableModel extends AbstractTableModel{
    ArrayList<BoothProduct> arrList;

    public ProductTableModel() {
    }

    public ProductTableModel(ArrayList<BoothProduct> arrList) {
        this.arrList = arrList;
    }
    
    @Override
    public int getRowCount() {
        return arrList.size();
    }

    @Override
    public int getColumnCount() {
        return 12;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Object value = null;
        BoothProductManage objProductManage = new BoothProductManage();
        BoothProduct objProduct = arrList.get(rowIndex);
        switch(columnIndex){
            case 0:
                value = objProduct.getId();
                break;
            case 1:
                value = objProduct.getName();
                break;
            case 2:
                value = "$ "+objProduct.getCost();
                break;
            case 3:
                value = objProduct.getSize();
                break;
            case 4:
                value = objProductManage.getSizeUnitById(objProduct.getSizeUnitMeasureId());
                break;
            case 5:
                value = objProduct.getWeight();
                break;
            case 6:
                value = objProductManage.getWeightUnitById(objProduct.getWeightUnitMeasureId());
                break;
            case 7:
                value = objProduct.getDescription();
                break;
            case 8:
                value = objProductManage.getCategoryNameById(objProduct.getCategoryID());
                break;
            case 9:
                value = objProductManage.getBoothNameById(objProduct.getBoothID());
                break;
            case 10:
                if(objProduct.getStatus() == 0)
                    value = "Nomarl";
                else
                    value = "Block";
                break;
            default:
                value = objProduct.getModifiedDate();
                break;
        
        }
        return value;
    }
    @Override
    public String getColumnName(int column) {
        String columName;
        switch(column){
            case 0:
                columName = "ID";
                break;
            case 1:
                columName = "Product Name";
                break;
            case 2:
                columName = "Cost";
                break;
            case 3:
                columName = "Size";
                break;
            case 4:
                columName = "Unit";
                break;
            case 5:
                columName = "Weight";
                break;
            case 6:
                columName = "Unit";
                break;
            case 7:
                columName = "Description";
                break;
            case 8:
                columName = "Category";
                break;
            case 9:
                columName = "Booth Name";
                break;
            case 10:
                columName = "Status";
                break;
            default:
                columName = "Modified Date";
                break;
        }
        return columName;
    }
}
